window.onload=function(){
    let username = document.getElementById("username")
    let password = document.getElementById("password")
    let name = username.value
    let pass = password.value
    let button = document.getElementsByTagName("button")[0]
    button.addEventListener("click", () => {
        let promise = new Promise((resolve, reject) => {
            let xhr = new XMLHttpRequest()
            xhr.open("GET", "http://172.19.14.60:8080/login" + "?username=" + name + "&password=" + pass, true)
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    console.log("请求成功")
                    resolve(xhr.responseText)
                }
            }
            console.log("代码1")
            xhr.send()
        })
        promise.then((res) => {
            console.log("success")
            console.log(res)
        }).catch(() => {
            console.log("err")
        }).finally(() => {
            console.log("both")
        })

    })

    setTimeout(() => {
        console.log("5")
    }, 5000)
}